import java.util.Arrays;

public class TestDemo {
    //StringBuffer或者StringBuilder-->String使用to.String
    public static String func1(){
        StringBuffer stringBuffer = new StringBuffer();
        return stringBuffer.toString();
    }
    //String-->StringBuffer或者StringBuilder使用构造方法
    public static StringBuffer func(){
        String s = "abcd";
        return new StringBuffer(s);
    }
    public static void main(String[] args) {

    }

    public static void main11(String[] args) {
        StringBuilder stringBuilder = new StringBuilder("abcde");
        System.out.println(stringBuilder);//abcde
        StringBuilder stringBuilder1 = new StringBuilder();
        stringBuilder1.append("abcde");
        System.out.println(stringBuilder1);//abcde
        stringBuilder1.append("123");
        System.out.println(stringBuilder1);//abcde123
    }


    public static void main10(String[] args) {
        String str = "   abd fhg ";
        String sub = str.trim();
        System.out.println(sub);//abd fhg

        String str1 = "abcDEF123";
        String sub1 = str1.toUpperCase();
        String sub2 = str1.toLowerCase();
        System.out.println(sub1);//ABCDEF123
        System.out.println(sub2);//abcdef123

        String str2 = "abc";
        String sub3 = str2.concat("cde");
        System.out.println(sub3);//abccde
        System.out.println(str2.isEmpty());//false
    }

    public static void main9(String[] args) {
        String str = "abcdefg";
        String sub = str.substring(2);
        String sub1 = str.substring(2,6);
        System.out.println(sub);//cdefg
        System.out.println(sub1);//cdef
    }

    public static void main8(String[] args) {
        String s = "192.95.25";
        String[] strings = s.split("\\.");
        String[] strings1 = s.split("\\.",2);

        for (String ret: strings) {
            System.out.println(ret);
            //192
            //95
            //25
        }
        for (String ret: strings1) {
            System.out.println(ret);
            //192
            //95.25

        }
        String str = "192\\25\\26\\4";
        String[] strings2 = str.split("\\\\");
        for (String ret: strings2) {
            System.out.println(ret);
            //192
            //25
            //26
            //4
        }

        String str1 = "java 12&21#hello";
        String[] strings3 = str1.split(" |&|#");
        for (String ret: strings3) {
            System.out.println(ret);
            //java
            //12
            //21
            //hello
        }


    }

    public static void main7(String[] args) {
        String str = "name=zhangsan&age=19";
        String[] strings = str.split("&");
        for (String s: strings) {
//            s:name=zhangsan   下次s:age=19
//            System.out.println(s);
            //name=zhangsan
            //age=19
            String[] ss = s.split("=");
            for (String tmp: ss) {
                System.out.println(tmp);
                //name
                //zhangsan
                //age
                //19
            }
        }
    }

    public static void main6(String[] args) {
        String str = "abcdabcabc";
        String s = str.replace("ab","pp");
        String s2 = str.replaceAll("ab","pp");
        String s1 = str.replace('a','t');
        String s3 = str.replaceFirst("a","n");
        System.out.println(s);//ppcdppcppc
        System.out.println(s2);//ppcdppcppc
        System.out.println(s1);//tbcdtbctbc
        System.out.println(s3);//nbcdabcabc
    }

    public static void main5(String[] args) {
        String str = "abcdbcdadeade";
        String tmp = "ade";
//        boolean flg = str.contains(tmp);
//        System.out.println(flg);//true
//        int index = str.indexOf(tmp);
//        int index1 = str.indexOf(tmp,5);
//        int index2 = str.indexOf(tmp,8);

//        System.out.println(index);//7
//        System.out.println(index1);//7
//        System.out.println(index2);//10
//        System.out.println(str.lastIndexOf(tmp));//10
//        System.out.println(str.lastIndexOf(tmp,8));//7
        System.out.println(str.startsWith("a"));//true
        System.out.println(str.startsWith("ade"));//false
        System.out.println(str.startsWith("d",3));//true
        System.out.println(str.endsWith("e"));//true
        System.out.println(str.endsWith("bde"));//false
    }

    public static void main4(String[] args) {
        String str = "abc";
        String str1 = "Abc";
        int ret = str.compareTo(str1);
        System.out.println(ret);//32

        System.out.println(str.equals(str1));//false
        System.out.println(str.equalsIgnoreCase(str1));//true
    }

    public static void main3(String[] args) {
        byte[] bytes = {97,98,99,100};
        String str = new String(bytes);
        System.out.println(str);//abcd
        String str1 = new String(bytes,1,3);
        System.out.println(str1);//bcd
        String str2 = "abcd";
        byte[] bytes1 = str2.getBytes();
        System.out.println(Arrays.toString(bytes1));//[97, 98, 99, 100]
    }

    public static boolean isNumberChar(String s){
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            boolean flg = Character.isDigit(c);
            if (flg == false){
                return false;
            }
        }
        return true;
    }
    public static void main2(String[] args){
        String s = "12356";
        System.out.println(isNumberChar(s));
    }

    public static void main1(String[] args) {
//        char[] chars = {'a','b','c'};
//        String str = new String(chars);
//        System.out.println(str);

//        char[] chars = {'a','b','c','d','e','f'};
//        String str = new String(chars,1,3);
//        System.out.println(str);//bcd

        String str = "abcde";
        char chars = str.charAt(2);
        //获取到2下标的字符
        System.out.println(chars);//c
        char[] chars1 = str.toCharArray();
        //把str指向的字符串对象变成字符数组
        System.out.println(Arrays.toString(chars1));//[a, b, c, d, e]


    }
}
